package com.xd.study.utility;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.widget.Toast;

/**
 * Created by DGF on 2015/5/5.
 */
public class MySQLiteOpenHelper extends SQLiteOpenHelper {

    private Context context;

    public MySQLiteOpenHelper(Context context, String name) {
        super(context, name, null, 1);

        this.context = context;
    }

    /**
     * 首次创建数据库时调用，一般可以把建库，建表操作放在这里
     * @param db
     */
    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL("create table if not exists stutb (_id integer primary key autoincrement, name text not null, age integer not null, sex text not null);");
    }

    /**
     * 当数据库的版本发生变化的时候调用
     * @param db
     * @param oldVersion
     * @param newVersion
     */
    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        Toast.makeText(this.context, "版本号变化："+newVersion, Toast.LENGTH_SHORT).show();
    }


}
